<template>
	<div class="outerTemplate">
		<goods-classify-header v-if="secList" :pageTitle="pageTitle"></goods-classify-header>

		<!--<goods-classify-list v-for="(item, index) in pageTree[type.list]"  :key="index" v-sdrag:real="{id: item.id, com: item.id}">-->

		<!--</goods-classify-list>-->
		<goods-classify-list v-if="secList" :comDetailDataList="secList"></goods-classify-list>
		<add-cart-animate></add-cart-animate>
	</div>
</template>

<script>
	import GoodsClassifyHeader from "./FoodGoodsClassifyHeader";
	import GoodsClassifyList from "./FoodGoodsClassifyList"
	import { mapGetters } from "vuex";
	import { getPageTree, initDomTree } from "../../utils/getPageTree";
	import AddCartAnimate from '@/real-components/AddCartAnimate'
	import axios from "axios";

	export default {

		data() {
			return {
				msg: '这是测试首页',
				page: "goodsClassify",
				type: {
					list: "list",
					header: "header"
				},
				timeObj: {
					mealLabel: '',
					endTime: ''
				},
				goodsCode: null, //分类编码
				pageTitle: "餐点", //分类名称
				foodtime: [],
				secList: [], //二级分类列表
				sourceDate: [],
				ids: '',
				secListid: ""
			}
		},
		components: {
			GoodsClassifyHeader,
			GoodsClassifyList,
			AddCartAnimate
		},
		methods: {
			mealTime() {
				var now = new Date()
				var year = now.getFullYear()
				var month = now.getMonth() + 1
				var day = now.getDate()
				var tomorrow = new Date(parseInt(now.setDate(day + 1)))
				var tomorrowYear = tomorrow.getFullYear()
				var tomorrowMonth = tomorrow.getMonth() + 1
				var tomorrowDay = tomorrow.getDate()
				var hour = now.getHours()
				var minute = now.getMinutes()
				var second = '00'
				var stringTime = year + '/' + month + '/' + day + ' '
				var isTime = hour + ':' + minute
				if(this.timeSlot('22:30', '24:00', isTime)) {
					this.timeObj.mealLabel = 'breakfast'
					this.timeObj.endTime = tomorrowYear + '/' + tomorrowMonth + '/' + tomorrowDay + ' ' + '8:30:00'
				} else if(this.timeSlot('00:00', '8:30', isTime)) {
					this.timeObj.mealLabel = 'breakfast'
					this.timeObj.endTime = stringTime + '8:30:00'
				} else if(this.timeSlot('8:30', '10:30', isTime)) {
					this.timeObj.mealLabel = 'tea'
					this.timeObj.endTime = stringTime + '10:30:00'
				} else if(this.timeSlot('10:30', '14:00', isTime)) {
					this.timeObj.mealLabel = 'lunch'
					this.timeObj.endTime = stringTime + '14:00:00'
				} else if(this.timeSlot('14:00', '16:30', isTime)) {
					this.timeObj.mealLabel = 'afterNTea'
					this.timeObj.endTime = stringTime + '16:30:00'
				} else if(this.timeSlot('16:30', '20:00', isTime)) {
					this.timeObj.mealLabel = 'dinner'
					this.timeObj.endTime = stringTime + '20:00:00'
				} else if(this.timeSlot('20:00', '22:30', isTime)) {
					this.timeObj.mealLabel = 'supper'
					this.timeObj.endTime = stringTime + '22:30:00'
				}
				return this.timeObj
			},

			timeSlot(beginTime, endTime, varTime) {
				var strb = beginTime.split(":");
				if(strb.length != 2) {
					return false;
				}
				var stre = endTime.split(":");
				if(stre.length != 2) {
					return false;
				}
				var strv = varTime.split(":");
				if(strv.length != 2) {
					return false;
				}
				var b = new Date();
				var e = new Date();
				var v = new Date();
				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);
				v.setHours(strv[0]);
				v.setMinutes(strv[1]);
				if((v.getTime() - b.getTime() >= 0 && (e.getTime() - v.getTime()) > 0)) {
					return true;
				} else {
					return false;
				}
			},

			/*-----------------------------------------------------*/

			/*queryMeal() {
				axios.post(api.local_host + '/resourceLevel/selectMeal', {
					enterpriseId: api.enterpriseId,
					mealLabel: this.timeObj.mealLabel
				}).then((res) => {
					this.sourceDate = res.data.data[0]
					console.log(this.sourceDate,"222222222222222222222222222")
					for(var i = 0; i < this.sourceDate.length; i++) {
							this.ids += this.sourceDate[i].goodsNo + ','
						}
						this.renderGood(this.ids)
				})
			},
			renderGood(ids) {
				var self=this
				axios.get(api.mall_goods_host + '/goodsRestApi/queryGoodsList?enterpriseid=' + api.enterpriseid + "&goodscode=" + ids).then((res) => {
					this.secList = res.data.data
					console.log(this.secList,"111111111111111111111111111")

				})

			},*/
			getmealdata() {
				this.secListid = this.$route.query.id
				var storeCodedata = localStorage.getItem('storeId')
				let url = window.api.goods_host + window.api.home_meal;
				let options = {
					method: "get",
					url,
					params: {
						enterpriseCode: window.api.enterpriseCode,
						storeCode: storeCodedata,
						relType: this.timeObj.mealLabel
					},
				}
				axios(options).then(data => {
					if(data.data.data.length > 0) {
						this.foodtime = data.data.data[0][`${this.secListid}`]
					}
					console.log(this.foodtime,222222)
					var obj={}
					for(var i = 0; i < this.foodtime.length; i++) {
						if(this.foodtime[i].relPosition == "content") {
							obj.goodsCode=this.foodtime[i].goodsCode //产品分类
							//obj.enterpriseName=this.foodtime[i].enterpriseCode // 商家名称---
							//obj.goodsId=this.foodtime[i].goodsid //产品ID
							obj.goodsName=this.foodtime[i].goodsVO.goodsName //产品名称
							obj.goodsPrice=this.foodtime[i].goodsVO.wsPrice //产品价格---
							obj.goodsUnit=this.foodtime[i].goodsVO.goodsUnit //产品单位
							obj.city=this.foodtime[i].goodsVO.prodArea //产地
							obj.shopName=this.foodtime[i].goodsVO.factoryName //商店名称---
							//obj.saleqty=this.foodtime[i].saleqty //库存  ---
							obj.goodsModel=this.foodtime[i].goodsVO.goodsModel // 商品型号
							//obj.goodsType=this.foodtime[i].goodstype //售价
							obj.normalPrice=this.foodtime[i].goodsVO.normalPrice //原价
							obj.mainPic=this.foodtime[i].publicityPicture //主图缩略图---
							//obj.featureLabel=this.foodtime[i].goodscode //特色标签
							this.secList.push(obj)
						}
					}
				})
			},
		},

		computed: {
			...mapGetters([
				"getDomTree",
			]),
			pageTree() {
				return getPageTree(this, this.page);
			},
		},

		watch: {

		},
		beforeCreate() {

		},
		created() {
			//初始化一级分类Code
		},
		mounted() {
			initDomTree(this.getDomTree[this.page]);
			this.mealTime()
			/*this.queryMeal()*/
			this.getmealdata()
		},
		updated() {
			//页面更新完毕
			initDomTree(this.getDomTree[this.page]);
		}
	}
</script>

<style>
	.outerTemplate {
		width: 100%;
		height: 100%;
		position: absolute;
		overflow: hidden;
	}
	
	.aui-list .aui-list-item {
		padding-left: 0px !important;
	}
</style>